﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <script type="text/javascript">
        function Person() {
            this.user_name = '王继光';
            this.user_age = 18;
        }
        Person.prototype.sayHi= function() {
            alert('我叫' + this.user_name + ',今年' + this.user_age);
        }
        var p = new Person();
        p.sayHi();

        function Student() {
            this.student_id = '001';
            this.student_score = 99;
        }
        //通过原型来实现继承
        Student.prototype = p; //这里只能写具体的persong对象（p）,而不能继承person
        Student.prototype.showS= function() {
            alert('学号：' + this.student_id + ',成绩：' + this.student_score);
        }
        var s = new Student();
        s.user_name = '黎明';
        s.sayHi();
        s.showS();
    </script>
<body>

</body>
</html>
